namespace OpenWaves
{
    public class RelativeUrlBuilder : UrlBuilder
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
        public static RelativeUrlBuilder From(RelativeUrl url)
        {
            var builder = new RelativeUrlBuilder
                              {
                                  Fragment = url.Fragment,
                                  Path = url.Path,
                              };

            foreach (var parameter in url.Query)
            {
                builder.AddParameter(parameter.Key, parameter.Value);
            }

            return builder;            
        }

        public new RelativeUrl ToUrl()
        {
            return this.BuildRelativeUrl();
        }

        private RelativeUrl BuildRelativeUrl()
        {
            return RelativeUrl.Create(this.Path, this.Fragment, this.Query);
        }

        protected override Url BuildUrl()
        {
            return this.BuildRelativeUrl();
        }
    }
}
